package memory;
import gui.GuiMain;

import java.util.ArrayList;

import storage.Storage;


public class Memory{
	public ArrayList<GenericEvents> memory = new ArrayList<GenericEvents>();

	//@author A0096677H
	// Adds a given GenericEvents item into the memory ArrayList
	// Updates quick view and saves to file
	public void add(GenericEvents item){
		assert item != null;

		String type = item.getType();

		memory.add(item);
		GuiMain.observerList.notifyUIs(type);
		Storage.saveToStorage(this);
	}

	//@author A0096677H
	// Returns GenericEvents object at index
	public GenericEvents get(int index){
		return memory.get(index);
	}

	//@author A0096677H
	// Returns ArrayList of GenericEvents used by memory
	public ArrayList<GenericEvents> getList(){
		return memory;
	}

	//@author A0096677H
	// Returns number of GenericEvents in memory (size)
	public int getSize(){
		return memory.size();
	}

	//@author A0096677H
	// Loads GenericEvents from save file into memory
	public void loadFromFile(Memory memory){
		assert memory != null;
		Storage.checkForFileExists(memory);
	}

	//@author A0096677H
	// Removes given item from memory
	public void remove(GenericEvents item){
		assert item != null;

		String type = item.getType();

		memory.remove(item);
		GuiMain.observerList.notifyUIs(type);
		Storage.saveToStorage(this);
	}

	//@author A0096677H
	// Swap out ArrayList used by memory with new given list
	public void setList(ArrayList<GenericEvents> list){
		memory = list;
	}

}
